function varargout = bc_2D(varargin)
% BC_2D M-file for bc_2D.fig
%      BC_2D, by itself, creates a new BC_2D or raises the existing
%      singleton*.
%
%      H = BC_2D returns the handle to a new BC_2D or the handle to
%      the existing singleton*.
%
%      BC_2D('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in BC_2D.M with the given input arguments.
%
%      BC_2D('Property','Value',...) creates a new BC_2D or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before bc_2D_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to bc_2D_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help bc_2D

% Last Modified by GUIDE v2.5 16-Apr-2012 12:49:48

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @bc_2D_OpeningFcn, ...
                   'gui_OutputFcn',  @bc_2D_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before bc_2D is made visible.
function bc_2D_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to bc_2D (see VARARGIN)

% Choose default command line output for bc_2D
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes bc_2D wait for user response (see UIRESUME)
% uiwait(handles.figure1);
global data;
data.param.Gcierre = true;

if (data.param.cust_temp==0 && data.param.temporal==0)
    set(handles.jp_inisolution,'Visible','off');
elseif data.param.cust_ini_sol
    set(handles.rb_custom_solution,'Value',1.0);
    set(handles.rb_const_solution,'Value',0.0);
    set(handles.edit_const_solution,'Enable','Off');
else
    set(handles.rb_const_solution,'Value',1.0);
    set(handles.edit_const_solution,'String',num2str(data.param.const_ini_sol{1}))
end

% --- Outputs from this function are returned to the command line.
function varargout = bc_2D_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global data;
data.param.Gcierre = false;

close bc_2D
geo_3

% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global data;
data.param.Gcierre = false;
correct=1;
if (data.param.ts_bc && data.param.ls_bc && data.param.bs_bc && data.param.rs_bc)
    
    %condicion inicial
    if (data.param.cust_temp) || (data.param.temporal ~= 0)
        if get(handles.rb_const_solution,'Value')
            if isempty(str2num(get(handles.edit_const_solution,'String')))
                warndlg('Initial Solution: Input must be numerical');
                correct=0;
                data.param.Gcierre = true;
            else
                const_is=str2num(get(handles.edit_const_solution,'String'));
                set(data.param,{'const_ini_sol'},num2cell({const_is}));
            end
        else
            filename = strcat([data.param.direc,'/custom_inisolution.m']);
            s = ['edit ' filename];
            eval(s)
            hh = warndlg('Custom initial solution must be programmed before run the problem. Matlab editor, with these files, has been opened.','caution','modal'); 
            uiwait(hh);
        end
    end
    
    % una vez conocidos los parametros, armo los patches de las CBs
    data.patchs(2) = Patch;
    xnod = cell2mat(get(data.mesh.nodes,'x'));
    icone = cell2mat(get(data.mesh.eles,'icone'));
    xmin = min(xnod); xmax = max(xnod);
    tol = 1e-6;
    %ifaceb: [index_ele nface_local]
    %face_con: [indx_node1 indx_node2]
    [ifaceb,face_con] = pfbou2d(xnod,icone,1);
    nodes_bou = rmdblist(m2v(face_con));
    nodes_bot  = find(abs(xnod(:,2)-xmin(2))<tol);
    nodes_top  = find(abs(xnod(:,2)-xmax(2))<tol);
    nodes_lef  = find(abs(xnod(:,1)-xmin(1))<tol);
    nodes_rig  = find(abs(xnod(:,1)-xmax(1))<tol);
    
    handle_param_cb2d;
    
    l_eleface = [];
    r_eleface = [];
    t_eleface = [];
    b_eleface = [];
    for i=1:size(face_con,1)
        if find(nodes_lef==face_con(i,1)) & find(nodes_lef==face_con(i,2))
            l_eleface = [l_eleface;ifaceb(i,:)];
        elseif find(nodes_rig==face_con(i,1)) & find(nodes_rig==face_con(i,2))
            r_eleface = [r_eleface;ifaceb(i,:)];
        elseif find(nodes_top==face_con(i,1)) & find(nodes_top==face_con(i,2))
            t_eleface = [t_eleface;ifaceb(i,:)];
        elseif find(nodes_bot==face_con(i,1)) & find(nodes_bot==face_con(i,2))
            b_eleface = [b_eleface;ifaceb(i,:)];
        else
            fprintf('error asignando caras de borde\n');
            exit();
        end
    end

    set(data.patchs(1),{'border','type','H','q','Tref','nodes','ele_faces'},num2cell({'LEFT',ltype,ls_H,ls_Tref,ls_q,nodes_lef,l_eleface}));
    set(data.patchs(2),{'border','type','H','q','Tref','nodes'},num2cell({'RIGHT',rtype,rs_H,rs_Tref,rs_q,nodes_rig,r_eleface}));
    set(data.patchs(3),{'border','type','H','q','Tref','nodes','ele_faces'},num2cell({'TOP',ttype,ts_H,ts_Tref,ts_q,nodes_top,t_eleface}));
    set(data.patchs(4),{'border','type','H','q','Tref','nodes'},num2cell({'BOTTOM',btype,bs_H,bs_Tref,bs_q,nodes_bot,b_eleface}));

else
    correct=0;
    warndlg('Border Condition: All sides should be defined');
    data.param.Gcierre = true;
end

if (correct)
    close bc_2D
    simul
end

% --- Executes on button press in rb_const_solution.
function rb_const_solution_Callback(hObject, eventdata, handles)
% hObject    handle to rb_const_solution (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of rb_const_solution
set(handles.edit_const_solution,'Enable','On')
set(handles.rb_custom_solution,'Value',0.0)

% --- Executes on button press in rb_custom_solution.
function rb_custom_solution_Callback(hObject, eventdata, handles)
% hObject    handle to rb_custom_solution (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of rb_custom_solution
set(handles.rb_const_solution,'Value',0.0)
set(handles.edit_const_solution,'Enable','Off')


function edit_const_solution_Callback(hObject, eventdata, handles)
% hObject    handle to edit_const_solution (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_const_solution as text
%        str2double(get(hObject,'String')) returns contents of edit_const_solution as a double


% --- Executes during object creation, after setting all properties.
function edit_const_solution_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_const_solution (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in rb_ts.
function rb_ts_Callback(hObject, eventdata, handles)
% hObject    handle to rb_ts (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of rb_ts
if(get(hObject,'Value'))
    set(handles.rb_rs,'Value',0.0)
    set(handles.rb_bs,'Value',0.0)
    set(handles.rb_ls,'Value',0.0)
    set(handles.rb_dc,'Value',1.0);
    set(handles.edit_dc,'Enable','On');
    set(handles.edit_dc,'String','');
    set(handles.rb_nc,'Value',0.0)
    set(handles.edit_nc,'Enable','Off');
    set(handles.edit_nc,'String','');
    set(handles.rb_rc,'Value',0.0);
    set(handles.edit_rc1,'Enable','Off')
    set(handles.edit_rc1,'String','');
    set(handles.edit_rc2,'Enable','Off');
    set(handles.edit_rc2,'String','');
    set(handles.edit_rc3,'Enable','Off');
    set(handles.edit_rc3,'String','');
end

% --- Executes on button press in rb_rs.
function rb_rs_Callback(hObject, eventdata, handles)
% hObject    handle to rb_rs (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of rb_rs
if(get(hObject,'Value'))
    set(handles.rb_ts,'Value',0.0)
    set(handles.rb_bs,'Value',0.0)
    set(handles.rb_ls,'Value',0.0)
    set(handles.rb_dc,'Value',1.0);
    set(handles.edit_dc,'Enable','On');
    set(handles.edit_dc,'String','');
    set(handles.rb_nc,'Value',0.0)
    set(handles.edit_nc,'Enable','Off');
    set(handles.edit_nc,'String','');
    set(handles.rb_rc,'Value',0.0);
    set(handles.edit_rc1,'Enable','Off')
    set(handles.edit_rc1,'String','');
    set(handles.edit_rc2,'Enable','Off');
    set(handles.edit_rc2,'String','');
    set(handles.edit_rc3,'Enable','Off');
    set(handles.edit_rc3,'String','');
end

% --- Executes on button press in rb_ls.
function rb_ls_Callback(hObject, eventdata, handles)
% hObject    handle to rb_ls (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of rb_ls
if(get(hObject,'Value'))
    set(handles.rb_ts,'Value',0.0)
    set(handles.rb_rs,'Value',0.0)
    set(handles.rb_bs,'Value',0.0)
    set(handles.rb_dc,'Value',1.0);
    set(handles.edit_dc,'Enable','On');
    set(handles.edit_dc,'String','');
    set(handles.rb_nc,'Value',0.0)
    set(handles.edit_nc,'Enable','Off');
    set(handles.edit_nc,'String','');
    set(handles.rb_rc,'Value',0.0);
    set(handles.edit_rc1,'Enable','Off')
    set(handles.edit_rc1,'String','');
    set(handles.edit_rc2,'Enable','Off');
    set(handles.edit_rc2,'String','');
    set(handles.edit_rc3,'Enable','Off');
    set(handles.edit_rc3,'String','');
end

% --- Executes on button press in rb_bs.
function rb_bs_Callback(hObject, eventdata, handles)
% hObject    handle to rb_bs (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of rb_bs
if(get(hObject,'Value'))
    set(handles.rb_ts,'Value',0.0)
    set(handles.rb_rs,'Value',0.0)
    set(handles.rb_ls,'Value',0.0)
    set(handles.rb_dc,'Value',1.0);
    set(handles.edit_dc,'Enable','On');
    set(handles.edit_dc,'String','');
    set(handles.rb_nc,'Value',0.0)
    set(handles.edit_nc,'Enable','Off');
    set(handles.edit_nc,'String','');
    set(handles.rb_rc,'Value',0.0);
    set(handles.edit_rc1,'Enable','Off')
    set(handles.edit_rc1,'String','');
    set(handles.edit_rc2,'Enable','Off');
    set(handles.edit_rc2,'String','');
    set(handles.edit_rc3,'Enable','Off');
    set(handles.edit_rc3,'String','');
end


function edit_dc_Callback(hObject, eventdata, handles)
% hObject    handle to edit_dc (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_dc as text
%        str2double(get(hObject,'String')) returns contents of edit_dc as a double


% --- Executes during object creation, after setting all properties.
function edit_dc_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_dc (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_nc_Callback(hObject, eventdata, handles)
% hObject    handle to edit_nc (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_nc as text
%        str2double(get(hObject,'String')) returns contents of edit_nc as a double


% --- Executes during object creation, after setting all properties.
function edit_nc_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_nc (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_rc2_Callback(hObject, eventdata, handles)
% hObject    handle to edit_rc2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_rc2 as text
%        str2double(get(hObject,'String')) returns contents of edit_rc2 as a double


% --- Executes during object creation, after setting all properties.
function edit_rc2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_rc2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_rc1_Callback(hObject, eventdata, handles)
% hObject    handle to edit_rc1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_rc1 as text
%        str2double(get(hObject,'String')) returns contents of edit_rc1 as a double


% --- Executes during object creation, after setting all properties.
function edit_rc1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_rc1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in rb_dc.
function rb_dc_Callback(hObject, eventdata, handles)
% hObject    handle to rb_dc (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of rb_dc
if(get(hObject,'Value'))
    set(handles.edit_dc,'Enable','On')
    set(handles.rb_nc,'Value',0.0)
    set(handles.rb_rc,'Value',0.0)
    set(handles.edit_nc,'Enable','Off')
    set(handles.edit_rc1,'Enable','Off')
    set(handles.edit_rc2,'Enable','Off')
    set(handles.edit_rc3,'Enable','Off')
    set(handles.edit_nc,'String','')
    set(handles.edit_rc1,'String','')
    set(handles.edit_rc2,'String','')
    set(handles.edit_rc3,'String','')
else
    set(handles.edit_dc,'Enable','Off')
end

% --- Executes on button press in rb_nc.
function rb_nc_Callback(hObject, eventdata, handles)
% hObject    handle to rb_nc (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of rb_nc
if(get(hObject,'Value'))
    set(handles.edit_nc,'Enable','On')
    set(handles.rb_dc,'Value',0.0)
    set(handles.rb_rc,'Value',0.0)
    set(handles.edit_dc,'Enable','Off')
    set(handles.edit_rc1,'Enable','Off')
    set(handles.edit_rc2,'Enable','Off')
    set(handles.edit_rc3,'Enable','Off')
    set(handles.edit_dc,'String','')
    set(handles.edit_rc1,'String','')
    set(handles.edit_rc2,'String','')
    set(handles.edit_rc3,'String','')
else
    set(handles.edit_nc,'Enable','Off')
end

% --- Executes on button press in rb_rc.
function rb_rc_Callback(hObject, eventdata, handles)
% hObject    handle to rb_rc (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of rb_rc
if(get(hObject,'Value'))
    set(handles.edit_rc1,'Enable','On')
    set(handles.edit_rc2,'Enable','On')
    set(handles.edit_rc3,'Enable','On')
    set(handles.rb_dc,'Value',0.0)
    set(handles.rb_nc,'Value',0.0)
    set(handles.edit_dc,'Enable','Off')
    set(handles.edit_nc,'Enable','Off')
    set(handles.edit_dc,'String','')
    set(handles.edit_nc,'String','')
else
    set(handles.edit_rc1,'Enable','Off')
    set(handles.edit_rc2,'Enable','Off')
    set(handles.edit_rc3,'Enable','Off')
end


function edit_rc3_Callback(hObject, eventdata, handles)
% hObject    handle to edit_rc3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_rc3 as text
%        str2double(get(hObject,'String')) returns contents of edit_rc3 as a double


% --- Executes during object creation, after setting all properties.
function edit_rc3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_rc3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pb_okc.
function pb_okc_Callback(hObject, eventdata, handles)
% hObject    handle to pb_okc (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global data;
correct=1;

if get(handles.rb_ts,'Value')
    if get(handles.rb_dc,'Value')
        if isempty(str2num(get(handles.edit_dc,'String')))
            correct=0;
        else
            ts_Tref=str2num(get(handles.edit_dc,'String'));
            ts_q = [];ts_H = [];
            data.param.ts_bc_set(true);
            data.param.ttype = 'DIRICHLET';
        end
    elseif get(handles.rb_nc,'Value')
        if isempty(str2num(get(handles.edit_nc,'String')))
            correct=0;
        else
            ts_q=str2num(get(handles.edit_nc,'String'));
            ts_Tref = [];ts_H = [];
            data.param.ts_bc_set(true);
            data.param.ttype = 'NEUMANN';
        end
    elseif get(handles.rb_rc,'Value')
        if isempty(str2num(get(handles.edit_rc1,'String')))
            correct=0;
        elseif isempty(str2num(get(handles.edit_rc2,'String')))
            correct=0;
        elseif isempty(str2num(get(handles.edit_rc3,'String')))
            correct=0;
        else
            ts_H=str2num(get(handles.edit_rc1,'String'));
            ts_Tref=str2num(get(handles.edit_rc2,'String'));
            ts_q=str2num(get(handles.edit_rc3,'String'));
            data.param.ts_bc_set(true);
            data.param.ttype = 'MIXED';
        end
    end
    set(data.param,{'ts_H','ts_Tref','ts_q'},num2cell({ts_H,ts_Tref,ts_q}));
elseif get(handles.rb_ls,'Value')
    if get(handles.rb_dc,'Value')
        if isempty(str2num(get(handles.edit_dc,'String')))
            correct=0;
        else
            ls_Tref=str2num(get(handles.edit_dc,'String'));
            ls_q = [];ls_H = [];
            data.param.ls_bc_set(true);
            data.param.ltype = 'DIRICHLET';
        end
    elseif get(handles.rb_nc,'Value')
        if isempty(str2num(get(handles.edit_nc,'String')))
            correct=0;
        else
            ls_q=str2num(get(handles.edit_nc,'String'));
            ls_Tref = [];ls_H = [];
            data.param.ls_bc_set(true);
            data.param.ltype = 'NEUMANN';
        end
    elseif get(handles.rb_rc,'Value')
        if isempty(str2num(get(handles.edit_rc1,'String')))
            correct=0;
        elseif isempty(str2num(get(handles.edit_rc2,'String')))
            correct=0;
        elseif isempty(str2num(get(handles.edit_rc3,'String')))
            correct=0;
        else
            ls_H=str2num(get(handles.edit_rc1,'String'));
            ls_Tref=str2num(get(handles.edit_rc2,'String'));
            ls_q=str2num(get(handles.edit_rc3,'String'));
            data.param.ls_bc_set(true);
            data.param.ltype = 'DIRICHLET';
        end
    end
    set(data.param,{'ls_H','ls_Tref','ls_q'},num2cell({ls_H,ls_Tref,ls_q}));
elseif get(handles.rb_bs,'Value')
    if get(handles.rb_dc,'Value')
        if isempty(str2num(get(handles.edit_dc,'String')))
            correct=0;
        else
            bs_Tref=str2num(get(handles.edit_dc,'String'));
            bs_q = [];bs_H = [];
            data.param.bs_bc_set(true);
            data.param.btype = 'DIRICHLET';
        end
    elseif get(handles.rb_nc,'Value')
        if isempty(str2num(get(handles.edit_nc,'String')))
            correct=0;
        else
            bs_q=str2num(get(handles.edit_nc,'String'));
            bs_Tref = [];bs_H = [];
            data.param.bs_bc_set(true);
            data.param.btype = 'NEUMANN';
        end
    elseif get(handles.rb_rc,'Value')
        if isempty(str2num(get(handles.edit_rc1,'String')))
            correct=0;
        elseif isempty(str2num(get(handles.edit_rc2,'String')))
            correct=0;
        elseif isempty(str2num(get(handles.edit_rc3,'String')))
            correct=0;
        else
            bs_H=str2num(get(handles.edit_rc1,'String'));
            bs_Tref=str2num(get(handles.edit_rc2,'String'));
            bs_q=str2num(get(handles.edit_rc3,'String'));
            data.param.bs_bc_set(true);
            data.param.btype = 'MIXED';
        end
    end
    set(data.param,{'bs_H','bs_Tref','bs_q'},num2cell({bs_H,bs_Tref,bs_q}));
elseif get(handles.rb_rs,'Value')
    if get(handles.rb_dc,'Value')
        if isempty(str2num(get(handles.edit_dc,'String')))
            correct=0;
        else
            rs_Tref=str2num(get(handles.edit_dc,'String'));
            rs_q = [];rs_H = [];
            data.param.rs_bc_set(true);
            data.param.rtype = 'DIRICHLET';
        end
    elseif get(handles.rb_nc,'Value')
        if isempty(str2num(get(handles.edit_nc,'String')))
            correct=0;
        else
            rs_q=str2num(get(handles.edit_nc,'String'));
            rs_Tref = [];rs_H = [];
            data.param.rs_bc_set(true);
            data.param.rtype = 'NEUMANN';
        end
    elseif get(handles.rb_rc,'Value')
        if isempty(str2num(get(handles.edit_rc1,'String')))
            correct=0;
        elseif isempty(str2num(get(handles.edit_rc2,'String')))
            correct=0;
        elseif isempty(str2num(get(handles.edit_rc3,'String')))
            correct=0;
        else
            rs_H=str2num(get(handles.edit_rc1,'String'));
            rs_Tref=str2num(get(handles.edit_rc2,'String'));
            rs_q=str2num(get(handles.edit_rc3,'String'));
            data.param.rs_bc_set(true);
            data.param.rtype = 'MIXED';
        end
    end
    set(data.param,{'rs_H','rs_Tref','rs_q'},num2cell({rs_H,rs_Tref,rs_q}));
end

if correct
    set(handles.rb_dc,'Value',1.0);
    set(handles.edit_dc,'Enable','On');
    set(handles.edit_dc,'String','');
    set(handles.rb_nc,'Value',0.0)
    set(handles.edit_nc,'Enable','Off');
    set(handles.edit_nc,'String','');
    set(handles.rb_rc,'Value',0.0);
    set(handles.edit_rc1,'Enable','Off')
    set(handles.edit_rc1,'String','');
    set(handles.edit_rc2,'Enable','Off');
    set(handles.edit_rc2,'String','');
    set(handles.edit_rc3,'Enable','Off');
    set(handles.edit_rc3,'String','');
    set(handles.rb_ts,'Value',1.0)
    set(handles.rb_ls,'Value',0.0)
    set(handles.rb_bs,'Value',0.0)
    set(handles.rb_rs,'Value',0.0)
else
    warndlg('Border Condition: Input must be numerical');
end


% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu1
global data;
option=get(hObject,'Value');
switch option
    case 1,
        set(handles.type,'String','-');
        set(handles.value1,'String','-');
        set(handles.value2,'String',' ');
        set(handles.value3,'String',' ');
    case 2,
        if (~isempty(data.param.ts_H{1}))
            set(handles.type,'String','Robin');
            set(handles.value1,'String',strcat('H:   ',num2str(data.param.ts_H{1})));
            set(handles.value2,'String',strcat('Tref:   ',num2str(data.param.ts_Tref{1})));
            set(handles.value3,'String',strcat('q:   ',num2str(data.param.ts_q{1}))); 
        elseif (~isempty(data.param.ts_Tref{1}))
            set(handles.type,'String','Dirichlet');
            set(handles.value1,'String',strcat('T:   ',num2str(data.param.ts_Tref{1})));
            set(handles.value2,'String',' ');
            set(handles.value3,'String',' ');
        elseif (~isempty(data.param.ts_q{1}))
            set(handles.type,'String','Neumman');
            set(handles.value1,'String',strcat('q:   ',num2str(data.param.ts_q{1})));
            set(handles.value2,'String',' ');
            set(handles.value3,'String',' ');    
        end
    case 3,
        if (~isempty(data.param.rs_H{1}))
            set(handles.type,'String','Robin');
            set(handles.value1,'String',strcat('H:   ',num2str(data.param.rs_H{1})));
            set(handles.value2,'String',strcat('Tref:   ',num2str(data.param.rs_Tref{1})));
            set(handles.value3,'String',strcat('q:   ',num2str(data.param.rs_q{1})));     
        elseif (~isempty(data.param.rs_Tref{1}))
            set(handles.type,'String','Dirichlet');
            set(handles.value1,'String',strcat('T:   ',num2str(data.param.rs_Tref{1})));
            set(handles.value2,'String',' ');
            set(handles.value3,'String',' ');
        elseif (~isempty(data.param.rs_q{1}))
            set(handles.type,'String','Neumman');
            set(handles.value1,'String',strcat('q:   ',num2str(data.param.rs_q{1})));
            set(handles.value2,'String',' ');
            set(handles.value3,'String',' ');
        end
    case 4,
        if (~isempty(data.param.bs_H{1}))
            set(handles.type,'String','Robin');
            set(handles.value1,'String',strcat('H:   ',num2str(data.param.bs_H{1})));
            set(handles.value2,'String',strcat('Tref:   ',num2str(data.param.bs_Tref{1})));
            set(handles.value3,'String',strcat('q:   ',num2str(data.param.bs_q{1})));   
        elseif (~isempty(data.param.bs_Tref{1}))
            set(handles.type,'String','Dirichlet');
            set(handles.value1,'String',strcat('T:   ',num2str(data.param.bs_Tref{1})));
            set(handles.value2,'String',' ');
            set(handles.value3,'String',' ');
        elseif (~isempty(data.param.bs_q{1}))
            set(handles.type,'String','Neumman');
            set(handles.value1,'String',strcat('q:   ',num2str(data.param.bs_q{1})));
            set(handles.value2,'String',' ');
            set(handles.value3,'String',' ');
          
        end
    case 5,
        if (~isempty(data.param.ls_H{1}))
            set(handles.type,'String','Robin');
            set(handles.value1,'String',strcat('H:   ',num2str(data.param.ls_H{1})));
            set(handles.value2,'String',strcat('Tref:   ',num2str(data.param.ls_Tref{1})));
            set(handles.value3,'String',strcat('q:   ',num2str(data.param.ls_q{1})));  
        elseif (~isempty(data.param.ls_Tref{1}))
            set(handles.type,'String','Dirichlet');
            set(handles.value1,'String',strcat('T:   ',num2str(data.param.ls_Tref{1})));
            set(handles.value2,'String',' ');
            set(handles.value3,'String',' ');
        elseif (~isempty(data.param.ls_q{1}))
            set(handles.type,'String','Neumman');
            set(handles.value1,'String',strcat('q:   ',num2str(data.param.ls_q{1})));
            set(handles.value2,'String',' ');
            set(handles.value3,'String',' ');  
        end
end

        
        

% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes when user attempts to close figure1.
function figure1_CloseRequestFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: delete(hObject) closes the figure
global data;
if (data.param.Gcierre)
    resp=questdlg('Está seguro que desea salir?','EduFEM');
    if strcmp(resp,'Yes')
        save(strcat(data.param.Gdirec,'/data'), 'data');
        delete(hObject);
    end
else
    delete(hObject);
end



